const jwt = require('jsonwebtoken');
const setting = require('./setting');
const verify = {
    setToKen(_id) {
        return new Promise(resolve => {
            let token = jwt.sign(
                {_id},
                setting.token.signKey,
                {expiresIn:setting.token.signTime}
            )
            resolve(token)
        })
    },
    getToken(token) {
        return new Promise((resolve,reject) => {
            if (!token.split(' ').length) {
                reject({error: 'The token value is empty'})
            } else {
                let data = jwt.verify(token.split(' ')[1], setting.token.signKey);
                resolve(data)
            }
        })
    }
}
module.exports = verify;